/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package webservice;

import database.Item;
import database.ItemFacadeLocal;
import database.ItemType;
import java.util.List;
import javax.ejb.EJB;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author Ewoud
 */
@WebService(serviceName = "ItemWebService")
public class ItemWebService {
    @EJB
    private ItemFacadeLocal itemFacade;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "create_bread")
    @Oneway
    public void create_bread(@WebParam(name = "name") String name, @WebParam(name = "description") String description, @WebParam(name = "price") float price) {
        Item newItem = new Item();
        newItem.setName(name);
        newItem.setPrice(price);
        newItem.setDescription(description);
        newItem.setType(ItemType.BREAD);
        itemFacade.create(newItem);
    }
    
    /**
     * Web service operation
     */
    @WebMethod(operationName = "create_pie")
    @Oneway
    public void create_pie(@WebParam(name = "name") String name, @WebParam(name = "description") String description, @WebParam(name = "price") float price) {
        Item newItem = new Item();
        newItem.setName(name);
        newItem.setPrice(price);
        newItem.setDescription(description);
        newItem.setType(ItemType.PIE);
        itemFacade.create(newItem);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "get_items")
    public String get_items() {
        String result = "";
        
        List<Item> items = itemFacade.findAll();
        for(Item currentItem : items){
            result += ( currentItem.getId()
                    +" | "+currentItem.getName()
                    +" | €"+currentItem.getPrice()
                    +" | "+currentItem.getDescription()+" | "
                    +currentItem.getType()+"\n" );
        }
        
        //TODO write your implementation code here:
        return result;
    }
}
